package com.ctg.payroll2.service.xlsImport.imp;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.ctg.payroll2.dao.xlsImport.*;
import com.ctg.payroll2.bean.po.ExcelInterfaceDetail;
import com.ctg.payroll2.bean.po.ExcelInterfaceMaster;
import com.ctg.payroll2.bean.po.ExcelPublicMaster;
import com.ctg.payroll2.bean.po.ExcelpublicDetail;
import com.ctg.payroll2.service.xlsImport.ExeclCustomizeService;
import com.ctg.platform.util.Page;
import com.sun.org.apache.xpath.internal.operations.Bool;

@SuppressWarnings("unchecked")
public class ExeclCustomizeServiceImpl implements ExeclCustomizeService {

	private ExcelInterfaceDetailDAO interfaceDetailDAO;

	private ExcelInterfaceMasterDAO excelInterfaceMasterDAO;

	private ExcelPublicDetailDAO excelPublicDetailDAO;

	private ExcelPublicMasterDAO excelPublicMasterDAO;

	private XlsPublicToosDAO xlspublicToosDAO;

	public XlsPublicToosDAO getXlspublicToosDAO() {
		return xlspublicToosDAO;
	}

	public void setXlspublicToosDAO(XlsPublicToosDAO xlspublicToosDAO) {
		this.xlspublicToosDAO = xlspublicToosDAO;
	}

	public ExcelInterfaceDetailDAO getInterfaceDetailDAO() {
		return interfaceDetailDAO;
	}

	public void setInterfaceDetailDAO(ExcelInterfaceDetailDAO interfaceDetailDAO) {
		this.interfaceDetailDAO = interfaceDetailDAO;
	}

	public ExcelInterfaceMasterDAO getExcelInterfaceMasterDAO() {
		return excelInterfaceMasterDAO;
	}

	public void setExcelInterfaceMasterDAO(
			ExcelInterfaceMasterDAO excelInterfaceMasterDAO) {
		this.excelInterfaceMasterDAO = excelInterfaceMasterDAO;
	}

	public ExcelPublicDetailDAO getExcelPublicDetailDAO() {
		return excelPublicDetailDAO;
	}

	public void setExcelPublicDetailDAO(
			ExcelPublicDetailDAO excelPublicDetailDAO) {
		this.excelPublicDetailDAO = excelPublicDetailDAO;
	}

	public ExcelPublicMasterDAO getExcelPublicMasterDAO() {
		return excelPublicMasterDAO;
	}

	public void setExcelPublicMasterDAO(
			ExcelPublicMasterDAO excelPublicMasterDAO) {
		this.excelPublicMasterDAO = excelPublicMasterDAO;
	}

	public void deleteInterFaceDetailsl(Object obj) {
		interfaceDetailDAO.deleteByPrimaryKey((Integer) obj);

	}

	public void deleteInterFaceMaster(Object obj) {
		excelInterfaceMasterDAO.deleteByPrimaryKey((Integer) obj);
	}

	public void deletePublicDetailsl(Object obj) {
		excelPublicDetailDAO.deleteByPrimaryKey((Integer) obj);

	}

	public void deletePublicMaster(Object obj) {
		excelPublicMasterDAO.deleteByPrimaryKey((Integer) obj);

	}

	public void insertInterFaceDetailsl(Object obj) {
		interfaceDetailDAO.insert((ExcelInterfaceDetail) obj);

	}

	public void insertInterFaceMaster(Object obj) {
		excelInterfaceMasterDAO.insert((ExcelInterfaceMaster) obj);
	}

	public void insertPublicDetailsl(Object obj) {
		excelPublicDetailDAO.insert((ExcelpublicDetail) obj);
	}

	public void insertPublicMaster(Object obj) {
		excelPublicMasterDAO.insert((ExcelPublicMaster) obj);
	}

	public void updateInterFaceDetailsl(Object obj) {
		interfaceDetailDAO.update((ExcelInterfaceDetail) obj);
	}

	public void updateInterFaceMaster(Object obj) {
		excelInterfaceMasterDAO.update((ExcelInterfaceMaster) obj);

	}

	public void updatePublicDetailsl(Object obj) {
		excelPublicDetailDAO.update((ExcelpublicDetail) obj);

	}

	public void updatePublicMaster(Object obj) {
		excelPublicMasterDAO.update((ExcelPublicMaster) obj);

	}

	public Page queryInterfaceDetailsl(Object paraMap, Integer start,
			Integer limit) {
		return interfaceDetailDAO.pagedQuery((Map<String, Object>) paraMap,
				start, limit);
	}

	public Page queryInterfaceMaster(Object paraMap, Integer start,
			Integer limit) {
		return excelInterfaceMasterDAO.pagedQuery(
				(Map<String, Object>) paraMap, start, limit);
	}

	public Page queryPublicDetailsl(Object paraMap, Integer start, Integer limit) {
		return excelPublicDetailDAO.pagedQuery((Map<String, Object>) paraMap,
				start, limit);
	}

	public Page queryPublicMaster(Object paraMap, Integer start, Integer limit) {
		return excelPublicMasterDAO.pagedQuery((Map<String, Object>) paraMap,
				start, limit);
	}

	/**
	 * Sami 根据Json字符串,Class类型, 参数名获取相应的beanList
	 * 
	 * @param jstr
	 *            json字符串
	 * @param clazz
	 *            需要转化的类型
	 * @param objname
	 *            参数名
	 * @return 相应bean的List
	 */
	public List<Object> getBeanListfromJson(String jstr, Class clazz,
			String objname) {
		List<Object> list = new ArrayList<Object>();
		JSONObject js = JSONObject.fromObject(jstr);
		JSONArray ja = js.getJSONArray(objname);
		for (Iterator<JSONObject> it = ja.iterator(); it.hasNext();) {
			Object obj = (Object) JSONObject.toBean(it.next(), clazz);
			list.add(obj);
		}
		return list;
	}

	/**
	 * 根据Json字符串,Class类型, 参数名获取相应的bean
	 * 
	 * @param jstr
	 *            json字符串
	 * @param clazz
	 *            需要转化的类型
	 * @param objname
	 *            参数名
	 * @return 相应的Bean
	 */
	public Object getBeanfromJson(String jstr, Class clazz, String objname) {
		Object obj = null;
		JSONObject js = JSONObject.fromObject(jstr);
		if (js != null) {
			obj = JSONObject.toBean(js.getJSONObject(objname), clazz);
		}
		return obj;
	}

	/*
	 * (non-Javadoc) 获取主键ID
	 * 
	 * @see com.ctg.payroll2.service.xlsImport.ExeclCustomizeService#getNewId()
	 */
	public Integer getNewId() {
		return excelPublicDetailDAO.getNewId();
	}

	public boolean deleteByExPublicId(int id) {
		try {
			excelPublicDetailDAO.deletepublicdetailByexPublicId(id);
			return true;
		} catch (Exception e) {
			return false;
		}

	}

	public Page queryPayClassByCompanyCode(Object paraMap, Integer start,
			Integer limit) {
		return xlspublicToosDAO.queryPayClassByCompanyCode(paraMap, start,
				limit);
	}

	public Page queryPayClassItemsByPayClassId(Object paraMap, Integer start,
			Integer limit) {
		return xlspublicToosDAO.queryPayClassItemsByPayClassId(paraMap, start,
				limit);
	}

	public Page querySocialByCompanyCode(Object paraMap, Integer start,
			Integer limit) {
		return xlspublicToosDAO.querySocialByCompanyCode(paraMap, start, limit);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.ctg.payroll2.service.xlsImport.ExeclCustomizeService#deleteInterfacedetailByexIntefaceId(java.lang.Object)
	 *      根据exIntefaceId 删除Interfacedetail 记录
	 */
	public Boolean deleteInterfacedetailByexIntefaceId(Object obj) {
		Boolean isDelete = false;
		if (obj != null) {
			interfaceDetailDAO.deleteInterfacedetailByexIntefaceId(obj);
			isDelete = true;
		}
		return isDelete;
	}

}
